﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Save2openExcel2007
{
    public partial class sOpendoc : Form
    {
        private libs lib = new libs();
        private string selectFile = "";
        public sOpendoc(string fileinfo)
        {
            InitializeComponent();
            this.selectFile = "";
            string files = fileinfo;
            files = files.Replace("[", "");
            files = files.Replace("]", "");
            files = files.Replace("u'", "");
            files = files.Replace("'", "");
            files = files.Replace(", ", ",");
            if ("" != files)
            {
                string[] filelist = files.Split(',');
                foreach (string fileitem in filelist)
                {
                    sDoclist.Items.Add(lib.ParseString(fileitem));
                }
            }
        }

        private void sOpen_Click(object sender, EventArgs e)
        {
            ListView.SelectedListViewItemCollection selectDoc = this.sDoclist.SelectedItems;
            if (selectDoc.Count > 0)
            {
                this.selectFile = selectDoc[0].Text;
                string status = lib.getFile(lib.getPost(), selectDoc[0].Text);
                if (status == "0")
                {
                    this.Close();
                }
                else
                {
                    MessageBox.Show("打开失败，请重试");
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("请选择需要打开的文件");
            }
        }

        private void sCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public string getSelF()
        {
            return this.selectFile;
        }
    }
}
